<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" type="text/css"
			href="<%=basePath%>common/ui/jquery-easyui-1.3.0/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css"
			href="<%=basePath%>common/ui/jquery-easyui-1.3.0/themes/icon.css">
		<script type="text/javascript"
			src="<%=basePath%>common/ui/jquery-easyui-1.3.0/jquery-1.7.2.min.js"></script>
		<script type="text/javascript"
			src="<%=basePath%>common/ui/jquery-easyui-1.3.0/jquery.easyui.min.js"></script>
		<script type="text/javascript"
			src="<%=basePath%>common/ui/jquery-easyui-1.3.0/locale/easyui-lang-zh_CN.js"></script>
		<style type="text/css">
a:link {
	text-decoration: none;
}

a:visited {
	text-decoration: none;
}

a:hover {
	text-decoration: underline;
}
</style>
		<script>
var win;
var form;
var grid;
		$(function(){
			grid = $('#test').datagrid({
				iconCls:'icon-save',
				nowrap: true,
				autoRowHeight: false,
				striped: true,
				collapsible:true,
				url:'<%=basePath%>manage/admin/user!dataList.action',
				sortName: 'code',
				sortOrder: 'desc',
				remoteSort: false,
				idField:'code',
				border:false,
				fit:true,
				fitColumns:true,
				pagination:true,
				rownumbers:true,
				idField:'beanId',
				singleSelect:true,
				frozenColumns:[[
				                {field:'ck',checkbox:true},
				                {title:'code',field:'beanId',width:80,sortable:true,align:'center',}
							]],
							columns:[[
			                            {field:'name',title:'头像',align:'center',width:80,editor:'numberbox'},
										{field:'loginName',title:'登录名',align:'center',width:80},
										{field:'enname',title:'昵称',align:'center',width:80},
										{field:'email',title:'邮箱',width:150,align:'center'},
										{field:'phone',title:'手机号',width:100,align:'center'},
										{field:'status',title:'状态',width:100,align:'center'},
										{field:'beanCreateTime',title:'注册时间',width:150,align:'center'},
										{field:'memo',title:'备注',width:150,align:'center'},
										{field:'opt',title:'操作',width:100,align:'center', rowspan:2,
											formatter:function(value,row,index){
											if(row.editing){
						                        var s ='<a href="javascript:void(0);" onclick="saveRow('+index+')" style="text-decoration: none;color: #800080;">保存</a>  ';
						                        var c ='<a href="javascript:void(0);" onclick="cancelRow('+index+')" style="text-decoration: none;color: #800080;">取消</a>';
						                        return s+c;
						                    }else{
						                        var e = '<a href="javascript:void(0);" onclick="editRow('+index+')" style="text-decoration: none;color: #800080;">编辑</a> ';
						                         var d = '<a href="javascript:void(0);" onclick="deleteRow('+index+')" style="text-decoration: none;color: #800080;">删除</a>';
						                         return e+d;
						                    }
											//return '<a href="javascript:void(0)" onclick="editSingle('+rowIndex+')"><span style="color:red">修改</span> </a>  <a href="javascript:void(0)" onclick="removeSingle('+row.beanId+')"><span style="color:red">删除</span></a>';
											}
										   
										}
									]],
				toolbar:[{
										text:'添加',
										iconCls:'icon-add',
										handler:newadd
									},'-',{
										text:'修改',
										iconCls:'icon-edit',
										handler:edit
									},'-',{
										text:'批量删除',
										iconCls:'icon-cancel',
										handler:remove
									},'-',{
										text:'批量冻结',
										iconCls:'icon-remove'
									}]
				
			});
			var p = $('#test').datagrid('getPager');
			$(p).pagination({
				onBeforeRefresh:function(){
					alert('before refresh');
				},
				pageSize: 10,//每页显示的记录条数，默认为10  
			    pageList: [10,15,20],//可以设置每页记录条数的列表  
			    beforePageText: '第',//页数文本框前显示的汉字  
			    afterPageText: '页    共 {pages} 页',  
			    displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',  
			});
			
			$('#btn-save,#btn-cancel').linkbutton();
			win = $('#user-window').window({
				closed:true,
				minimizable:false,
				maximizable:false,
				modal: true,            //模式窗口：窗口背景不可操作  
		        collapsible : false,     //可折叠，点击窗口右上角折叠图标将内容折叠起来  
		        resizable : false        //可拖动边框大小
			});
			
			form = win.find('form');
		});
		function resize(){
			$('#test').datagrid('resize', {
				width:700,
				height:400
			});
		}
		
		function newadd(){
			win.window('open');
			form.form('clear');
			form.url = '<%=basePath%>manage/admin/admin!preservation.action';
		}
		function editSingle(rowIndex){  
			$('#test').datagrid('beginEdit',rowIndex);
			//alert(Number(rowIndex));
			 //var row = grid.datagrid('selectRecord',rowIndex);
			 //grid.datagrid('selectRow',rowIndex);
			 //$('#test').datagrid('unselectAll');
			 // $('#test').datagrid('selectRow',Number(rowIndex));
		}  
		function edit(){  
		    var row = grid.datagrid('getSelected');  
		    var rowIndex = grid.datagrid('getRowIndex', row);
		    if (row){  
		    	newadd();
		        $('#enname').val(row.enname);
		        $('#loginName').val(row.loginName);
		        $('#phone').val(row.phone);
		        $('#email').val(row.email);
		        $('#password').val(row.password);
		        $('#address').val(row.address);
		        $('#memo').val(row.memo);
		        $('#beanId').val(row.beanId);
		    } else { 
		    	$.messager.alert('错误提示',"请先选择",'error');   
		    } 
		}  
		function save(){  
		    form.form('submit', {  
		        url:form.url,  
		        success:function(data){  
		            eval('data='+data);  
		            if (data.success){  
		                grid.datagrid('reload');  
		                win.window('close'); 
		                $('#user-window').window('close');
		            } else {  
		                $.messager.alert('错误',data.msg,'error');  
		            }  
		        }  
		    });  
		} 
		function removeSingle(id){
			var mycars=new Array();
			mycars[0]=id;
			del(mycars);
		} 
		
		function remove(){
			var ids = new Array();
			var rows = $('#test').datagrid('getSelections');
			for(var i=0;i<rows.length;i++){
				ids.push(rows[i].beanId);
			}
		    del(ids);
			   
		} 
		function del(ids){
			if(ids.length>0){
				$.messager.confirm('提示', '确认删除么?', function(r){
		    		if (r){
			    		$.ajax({     
			    		    url:'<%=basePath%>manage/admin/admin!remove.action',     
			    		    type:'post',     
			    		    data:"ids="+ids.join(':'),    
			    		    async : false, //默认为true 异步     
			    		    error:function(){     
			    		       $.messager.alert('错误提示',data.msg,'error');
			    		    },     
			    		    success:function(data){     
			    		       grid.datagrid('reload');      
			    		    }  
			    		});
					}
		    		
				});				   
				}else{
			       $.messager.alert('提示','请选择一行数据','error');
			    }
		}
		function closeWindow(){  
		    win.window('close');  
		} 
	</script>
	</head>

	<body>
		<table id="test"></table>


		<!-- form 部分 -->
		<div id="user-window" title="用户窗口">
			<div style="padding: 20px 20px 20px 20px;">
				<form method="post">
					<input type="hidden" name="user.beanId" id="beanId" />
					<table>
						<tr>
							<td>
								名称
							</td>
							<td>
								<input name="user.enname" id="enname" validType="length[5,12]"
									class="easyui-validatebox" required="true"></input>
							</td>
						</tr>
						<tr>
							<td>
								登录名
							</td>
							<td>
								<input name="user.loginName" id="loginName"
									validType="length[5,12]" class="easyui-validatebox"
									required="true"></input>
							</td>
						</tr>
						<tr>
							<td>
								密码
							</td>
							<td>
								<input name="user.password" id="password"
									validType="length[5,12]" class="easyui-validatebox"
									required="true"></input>
							</td>
						</tr>
						<tr>
							<td>
								电话
							</td>
							<td>
								<input name="user.phone" id="phone" validType="length[5,30]"
									class="easyui-validatebox" required="true" />
							</td>
						</tr>
						<tr>
							<td>
								邮箱
							</td>
							<td>
								<input name="user.email" id="email" class="easyui-validatebox"
									required="true" validType="email" />
							</td>
						</tr>
						<tr>
							<td>
								地址
							</td>
							<td>
								<input name="user.address" id="address" />
							</td>
						</tr>
						<tr>
							<td>
								备注
							</td>
							<td>
								<input name="user.memo" id="memo" />
							</td>
						</tr>
					</table>
				</form>
				<div style="text-align: center; padding: 5px;">
					<a href="javascript:void(0)" onclick="save()" id="btn-save"
						icon="icon-save">保存</a>
					<a href="javascript:void(0)" onclick="closeWindow()"
						id="btn-cancel" icon="icon-cancel">取消</a>
				</div>
			</div>

		</div>
		<!-- form 部分 -->
	</body>
</html>
